﻿using Moki;
using Moki.Tests.Model;
using NUnit.Framework;
using System;
using Moki.Exceptions;

namespace Moki.Specification
{
    [TestFixture]
    public class ExceptionsSpec
    {
        [TearDown]
        public void TearDown()
        {
            Mock.CleanUp();
        }

        [Test]
        [ExpectedException(typeof(MockTypeException), ExpectedMessage = "Can't mock class", MatchType = MessageMatch.StartsWith)]
        public void Should_throw_mock_type_exception_when_create_by_ref_obj()
        {
            MarshallByRefTestClass test = Mock.Create<MarshallByRefTestClass>();
        }

        [Test]
        [ExpectedException(typeof(MockTypeException), ExpectedMessage = "Can't mock sealed class", MatchType = MessageMatch.StartsWith)]
        public void Should_throw_mock_type_exception_when_create_sealed_class()
        {
            SealedClass test = Mock.Create<SealedClass>();
        }

        [Test]
        [ExpectedException(typeof(MemberTypeException), ExpectedMessage = "Can't stub or verify non-virtual member", MatchType = MessageMatch.StartsWith)]
        public void Should_throw_member_type_exception_when_stub_non_virtual()
        {
            PartialMockTest test = Mock.Create<PartialMockTest>();

            Mock.WhenCalled(() => test.NonVirtualMethod()).Returns("aaa");

        }

        [Test]
        [ExpectedException(typeof(MemberTypeException), ExpectedMessage = "Can't stub or verify non-virtual member", MatchType = MessageMatch.StartsWith)]
        public void Should_throw_member_type_exception_when_verify_non_virtual()
        {
            PartialMockTest test = Mock.Create<PartialMockTest>();

            test.NonVirtualMethod();

            Mock.VerifyCalled(() => test.NonVirtualMethod());

        }

     


    }
}
